<?php

/**
 * Description of TestAction
 *
 * @author Administrator
 */
class TestAction extends PublicAction {

    public function index() {

        import('@.ORG.Http');
        //$url = 'http://api.west263.com/api/west263.asp';
        $url = 'http://now.net.cn/domain/domaincheck.php?query=west263.com';
        $conf = array();
        //$conf['']

        $return = Http::fsockopen_download($url,$conf);
         
        //$return = auto_charset($return, 'GB2312', 'utf8');
        $return = simplexml_load_string($return);
        print_r($return);
//         echo auto_charset($return, 'GB2312', 'utf8');

        exit;
        //要post的数据
        $argv = array(
            'var1' => 'abc',
            'var2' => '你好吗');

        echo $this->PostData($argv, "1000", "aip@hichina.com", "mypassword");
    }

    /*
      $arg,$userid,$email,$password 分别表示：
      用户post的数据，您的id，您的email，您的密码
     */

    function PostData($arg, $userid, $email, $password) {
        //构造要post的字符串
        $params = "";
        foreach ($arg as $key => $value) {
            $params.= "&" . $key . "=";
            $params.= urlencode($value);
        }
        $params = substr($params, 1);
        $params.="&userid=" . $userid;
        $sVTime = date("YmdHi", time());
        $params.="&vtime=" . $sVTime;
        $params.="&userstr=" . md5($userid . $password . $email . $sVTime);

        $length = strlen($params);

        //以下参数请按西部数码最终 API 发布地址进行修改
        $apiHost = "api.west263.com";
        $apiPort = 80;
        $apiUrl = "/api/west263.asp";

        $fp = fsockopen($apiHost, $apiPort, $errno, $errstr, 10) or exit($errstr . "--->" . $errno);

        //构造post请求的头
        $header = "POST " . $apiUrl . " HTTP/1.1\r\n";
        $header .= "Host:" . $apiHost . "\r\n";
        $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
        $header .= "Content-Length: " . $length . "\r\n";
        $header .= "Connection: Close\r\n\r\n";
        //添加post的字符串
        $header .= $params . "\r\n";
        //发送post的数据
        fputs($fp, $header);
        $inheader = 1;
        $ret = "";
        while (!feof($fp)) {
            $line = fgets($fp, 1024); //去除请求包的头只显示页面的返回数据
            if ($inheader && ($line == "\n" || $line == "\r\n")) {
                $inheader = 0;
            }
            if ($inheader == 0) {
                $ret.=$line;
            }
        }
        fclose($fp);
        return $ret;
    }

}

?>
